//
//  LLStatusForwardCell.swift
//  WeiBoShiBing
//
//  Created by Bingo on 15/11/1.
//  Copyright © 2015年 Bingo. All rights reserved.
//

import UIKit
//设置转发微博的cell格式
class LLStatusForwardCell:LLStatusCell{

    override var status: LLStatus?{
        didSet{
        
//            print("\(status?.id),子类监视器")
            let name = status?.retweeted_status?.user?.name ?? "名称为空"
            let text = status?.retweeted_status?.text ?? "内容为空"
            
//            forwardLabel.text = "@\(name):\(text)"
            
            let nameAttr = NSMutableAttributedString(string: "@\(name): ")
            
            let arrtrText = LLEmoticon.emticonStringToEmotionAttrString(text, font: UIFont.systemFontOfSize(16))
            
            nameAttr.appendAttributedString(arrtrText)
            
            forwardLabel.attributedText = nameAttr
        }
    }
    //准备ui
    override func prepareUI() {
        super.prepareUI()
        
        contentView.insertSubview(bkgButoon, belowSubview: pictureView)
        
        contentView.addSubview(forwardLabel)
        //添加约束
        bkgButoon.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        bkgButoon.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bkgButoon, size: nil, offset: CGPoint(x: 8, y: 8))
        
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 0, height: 0), offset: CGPoint(x: 0, y: 8))
        
        pictureViewWidthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
    }
    //懒加载
    private lazy var bkgButoon:UIButton = {
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 0.9, alpha: 1)
        return button
    }()
    
    private lazy var forwardLabel:FFLabel = {
        let label = FFLabel()
        label.textColor = UIColor.darkGrayColor()
        label.numberOfLines = 0
        
        label.labelDelegate = self
        return label
    }()

}